#include "c3b_data_receive.h"

#ifdef BUILD_FOR_C3B
#include "ca/basic/libbasic.h"
#include "ca/protocol/protocol.h"
#include "ca/protocol/publisher.h"
#endif

using namespace DcAdr;

C3bDataReceive::C3bDataReceive(/* args */)
{
}

C3bDataReceive::~C3bDataReceive()
{
}

void C3bDataReceive::init()
{
#ifdef BUILD_FOR_C3B
    ca::basic::Basic::Init();
    ca::basic::Basic::Init("my yaml global config file path");

    /**共享内存数据订阅设置 */
    vector<string> shm_topics = {"topic1", "topic2"}; // topic名称
    ProtocolConfig cfg1;                              // 通信协议配置
    cfg1.type = ProtoType::kShm;
    cfg1.topics.emplace_back(topic);
    auto subscriber = Subscriber::create(cfg1); // 加载协议配置，创建Subscriber

    /**获取订阅的数据 */
    auto msgptr =
        subscriber->subscribe<MyProtobufMessage>("topic1",
                                                 2000); // 订阅数据。等待最多2000ms，如果还没有取到数据就立即返回
    if (msgptr != nullptr)
    {
        auto &msg = *msgptr;
        // DO Something
    }
#endif
}